home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_200 / 286_01 / earc2.c < prev    next >
Text File  |  1989-05-23  |  3KB  |  123 lines

  1. #include <stdio.h>
  2. #include <gds.h>
  3.  
  4. extern int ARCSTTX, ARCSTTY, ARCENDX, ARCENDY, ARCSTTR, ARCENDR;
  5.  
  6. struct cpoint {
  7.     int point,state,region;
  8. };
  9.  
  10. extern int arcreg[], regbit[];
  11.  
  12. extern unsigned int TANVAL[];
  13.  
  14. #define on 1
  15. #define off 0
  16.  
  17. Earc2(ctrx,ctry,a,b,st_deg,deg)
  18. int ctrx,ctry,a,b;
  19. register int st_deg,deg;
  20. {
  21.     int arcp;
  22.     int region2, rotreg;
  23.     int count1,count2,curcnt;
  24.     unsigned int temp;
  25.     struct cpoint pnt1, pnt2, pnt3, pnt4;
  26.  
  27.     if (deg<=0) {
  28. setnull:
  29.         LASTX=ctrx;
  30.         LASTY=ctry;
  31.         ARCSTTX=ARCSTTY=ARCENDX=ARCENDY=0;
  32.         return;
  33.     }
  34.     if (deg>=360) Earc2(ctrx,ctry,a,b,0xff);
  35.     ctrx+=ORGX; 
  36.     ctry+=ORGY;
  37.  
  38.     if ((ctrx+a < WINX1) || (ctrx-a > WINX2) ||
  39.         (ctry+b < WINY1) || (ctry-b > WINY2)) goto setnull;
  40.  
  41.     seteptr(1);
  42.     arcp=st_deg/360;
  43.     st_deg-=arcp*360;
  44.     if (st_deg<0) st_deg+=360;
  45.     if (a<b)
  46.         temp=(int) (( ((long) a << 16)/b+1)>>1);
  47.     else
  48.         temp=(int) (( ((long) b <<16)/a+1)>>1);
  49.     for(count1=0, count2=46; count1+1 != count2; ) {
  50.         curcnt=(count1+count2)>>1;
  51.         if (temp>=TANVAL[curcnt])
  52.             count1=curcnt;
  53.         else
  54.             count2=curcnt;
  55.     }
  56.     if (a>b) curcnt=90-count1; else curcnt=count1;
  57.     rotreg=(st_deg/90)<<1;
  58.     st_deg %= 90;
  59.     if (st_deg>=curcnt) {
  60.         rotreg++;
  61.         deg-=curcnt;
  62.         count1=90-curcnt;
  63.         count2=curcnt;
  64.     } else {
  65.         count1=curcnt;
  66.         count2=0;
  67.     }
  68.     deg += st_deg;
  69.     region2=(deg/90)<<1;
  70.     deg %= 90;
  71.     if (deg>=count1) {
  72.         region2++;
  73.     }
  74.     deg+=count2;
  75.     if (deg>=90) deg-=90;
  76.     arcp= 0xff ^ arcreg[region2];
  77.     arcp=arcp<<rotreg;
  78.     arcp=(arcp & 0xff) | ((arcp & 0xff00) >> 8);
  79.     region2=(region2+rotreg) & 0x07;
  80.     ARCSTTR=rotreg;
  81.     ARCENDR=region2;
  82.     setpnt(&pnt1,&pnt3,rotreg,on,off,a,b,90-st_deg,st_deg);
  83.     setpnt(&pnt2,&pnt4,region2,off,on,a,b,90-deg,deg);
  84.     if (pnt1.point==0) {
  85.         ARCSTTX=0;
  86.         ARCSTTY=b;
  87.     }
  88.     if (pnt2.point==0) {
  89.         ARCENDX=0;
  90.         ARCENDY=b;
  91.     }
  92.     adjpnt(&arcp,&pnt1,&pnt2,(st_deg<deg),rotreg);
  93.     if (pnt3.point==0) {
  94.         ARCSTTX=0;
  95.         ARCSTTY=a;
  96.     }
  97.     if (pnt4.point==0) {
  98.         ARCENDX=0;
  99.         ARCENDY=a;
  100.     }
  101.     adjpnt(&arcp,&pnt3,&pnt4,(st_deg<deg),rotreg);
  102.     Ell(ctrx,ctry,a,b,arcp & 0xff,STYLE,&pnt1,&pnt2,&pnt3,&pnt4);
  103.     if ((pnt1.region & 0xff) && (pnt1.point >= 0)) {
  104.         ARCSTTX=LASTX2;
  105.         ARCSTTY=LASTY2;
  106.     }
  107.     if ((pnt2.region & 0xff) && (pnt2.point >= 0)) {
  108.         ARCENDX=LASTX2;
  109.         ARCENDY=LASTY2;
  110.     }
  111.     if ((pnt3.region & 0xff) && (pnt3.point >= 0)) {
  112.         ARCSTTX=LASTX;
  113.         ARCSTTY=LASTY;
  114.     }
  115.     if ((pnt4.region & 0xff) && (pnt4.point >= 0)) {
  116.         ARCENDX=LASTX;
  117.         ARCENDY=LASTY;
  118.     }
  119.     LASTX=ctrx;
  120.     LASTY=ctry;
  121. }
  122.  
  123.